package org.falak.ui;

import java.io.IOException;

import org.falak.FalakCallerID.R;
import org.falak.data.DataBaseHelper;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
	// The Android's default system path of your application database.
	// private static String DB_PATH = "/data/data/org.falak.FalakCallerID/databases/";
	private static String DB_NAME = "CallerID_DB";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		// Add the update button
		final Button update = (Button) findViewById(R.id.update);
		update.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (MainActivity.this.deleteDatabase(DB_NAME)) {
					try {
						DataBaseHelper data = new DataBaseHelper(
								MainActivity.this);
						data.createDataBase();
						data.close();
						Toast.makeText(MainActivity.this, "DB Updated",
								Toast.LENGTH_SHORT).show();
					} catch (IOException e) {
					}
				} else {
				}
			}
		});

		// Add the Hide Me button
		final Button hide = (Button) findViewById(R.id.hide);
		hide.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				MainActivity.this.finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.mymenu, menu);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.exit:
			this.finish();
			return true;
		default:
			return super.onContextItemSelected(item);
		}
	}

}